#!/bin/bash

# zabbix钉钉自定义机器人报警，将此脚本放入/usr/lib/zabbix/alertscripts/目录下，给予执行权限
# text是内容，对应zabbix里的{ALERT.MESSAGE}参数
# title是标题，对应该zabbix里的{ALERT.SUBJECT}
# picture_url是图片url
# content_url是点击标题会跳转到对应url

webhook='https://oapi.dingtalk.com/robot/send?access_token=dd53f2b4476062921174157a545e8ef3c285226da8c95c5eedcf5e3e6e35d7e1'

text=$2
title=$1
picture_url='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.sayloving.com%2Fuploads%2Fallimg%2F20171220%2F1513758710130558.jpg&refer=http%3A%2F%2Fwww.sayloving.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627091632&t=a74822dcc463f70ec32cce3980d5d270'

content_url='http://106.52.170.233/zabbix/hosts.php?ddreset=1'

function rebot() {
    curl $webhook -H 'Content-Type: application/json' -d "
        {
                'msgtype': 'link', 
                'link': {
                        'text': '$text',
                        'title': '$title', 
                        'picUrl': '$picture_url', 
                        'messageUrl': '$content_url'
                },
		'at': {
			'isAtAll': true
		}
        }"
}

rebot
